#include "stones.h"
#include <QPainter>

Stones::Stones(int color)
{
    c = color;
    rect = new QRectF(0,0,28,28);

    setZValue(1);
}

int Stones::getColor()
{
    return c;
}

QRectF Stones::boundingRect() const
{
    return *rect;
}

QPainterPath Stones::shape() const
{
    QPainterPath path;
    path.addRoundRect(*rect, 99, 99);
    return path;
}

void Stones::paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option, QWidget *widget)
{


    painter->setRenderHint(QPainter::Antialiasing, true);
    if(c == 1)
    {
        /*QGradientStops stops;
        stops << QGradientStop(0.00, QColor::fromRgba(0xffffffff));
        stops << QGradientStop(0.11, QColor::fromRgba(0xfff9ffa0));
        stops << QGradientStop(0.13, QColor::fromRgba(0xfff9ff99));
        stops << QGradientStop(0.14, QColor::fromRgba(0xfff3ff86));
        stops << QGradientStop(0.49, QColor::fromRgba(0xff93b353));
        stops << QGradientStop(0.87, QColor::fromRgba(0xff264619));
        stops << QGradientStop(0.96, QColor::fromRgba(0xff0c1306));
        stops << QGradientStop(1.00, QColor::fromRgba(0));*/

        QRadialGradient gradient(14, 14, 14, 8, 8); //gradient makes stones somewhat 3D ;p
        //gradient.setStops(stops);
        gradient.setColorAt(0, QColor(140,140,140,255));
        gradient.setColorAt(0.4, QColor(50,50,50,255));
        gradient.setColorAt(0.6, QColor(30,30,30,255));
        gradient.setColorAt(0.8, QColor(20,20,20,255));
        gradient.setColorAt(1, QColor(10,10,10,255));
        QBrush brush(gradient);

        painter->setPen(QPen(QColor(10,10,10,255), 1, Qt::SolidLine, Qt::RoundCap));
        painter->setBrush(gradient);
        //painter->setBrush(QBrush(Qt::black, Qt::SolidPattern));
        painter->drawEllipse(0,0,28,28);
    }
    if(c == -1)
    {
        QRadialGradient gradient(14, 14, 14, 8, 8);
        gradient.setColorAt(0, QColor(245,245,245,255));
        gradient.setColorAt(0.3, QColor(235,235,235,255));
        gradient.setColorAt(0.6, QColor(220,220,220,255));
        gradient.setColorAt(1, QColor(210,210,210,255));
        QBrush brush(gradient);

        painter->setPen(QPen(QColor(210,210,210,255), 1, Qt::SolidLine, Qt::RoundCap));
        painter->setBrush(gradient);
        //painter->setBrush(QBrush(Qt::white, Qt::SolidPattern));
        painter->drawEllipse(0,0,28,28);
    }
}
